﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

namespace Future.FormBase
{
    public class MenuStripUtils
    {
        /// <summary>
        /// 跟据菜单显示名称在菜单集合中查找菜单对象
        /// </summary>
        /// <param name="mainMenu"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static ToolStripMenuItem FindMenuItemByText(MenuStrip mainMenu, string text)
        {
            foreach (ToolStripItem item in mainMenu.Items)
            {
                if (item.Text == text)
                    return (ToolStripMenuItem)item;
            }
            return null;
        }

        /// <summary>
        /// 是否有子菜单.
        /// </summary>
        public static bool IsSubMenuOwner(ToolStripItem item)
        {
            if (item is ToolStripMenuItem)
            {
                if (((ToolStripMenuItem)item).DropDownItems.Count > 0)
                    return true;
            }
            return false;
        }
    }
}
